package com.fc.design.decorator;

/**
 * <p> Author：lidongxu </p>
 * <p> Title：</p>
 * <p> Description：</p>
 * <p> Create Time：2020-04-07 09:28 </p>
 */
public class DecoratorTest {

    public static void main(String[] args) {
        Component p = new ConcreteComponent();
        p.operation();
        System.out.println("---------------------------------");
        Component d = new ConcreteDecorator(p);
        d.operation();
    }
}

interface Component {
    public void operation();
}

class ConcreteComponent implements Component {
    public ConcreteComponent() {
        System.out.println("具体构建角色");
    }

    public void operation() {
        System.out.println("调用具体构建角色的方法");
    }
}

class Decorator implements Component {
    private Component component;

    public Decorator(Component component) {
        this.component = component;
    }

    public void operation() {
        component.operation();
    }
}

class ConcreteDecorator extends Decorator {
    public ConcreteDecorator(Component component) {
        super(component);
    }

    public void operation() {
        super.operation();
        addedFunction();
    }

    public void addedFunction() {
        System.out.println("为具体构建角色增加额外功能");
    }
}
